/**
 * Created by yanjd on 2017/8/1.
 */
let api = {}

/**
 * 活动专题开关获取
 * @param state
 * @param commit
 * @param params = {topicTitle: 活动标题}
 * @returns {Promise}
 * @constructor
 */
api.MG_GET_KING_SWITCH = function ({state, commit, rootState}, params) {
  return new Promise((resolve, reject) => {
    rootState.axios.get(rootState.CONSTANTS.APISpecial + 'specialTopic/getSpecialTopic', {params}).then(res => {
      res = res.data
      resolve(res.specialTopicEOList || [])
    }, () => {
      console.error('手游活动专题接口请求错误 (╯‵□′)╯︵┻━┻')
      resolve([])
    })
  })
}

/**
 *  王者荣耀活动页 主页5项
 * @param state
 * @param commit
 * @param params
 * @returns {Promise} 无
 * @constructor
 */
api.MG_GET_KING_HOME = function ({state, commit, rootState}, params) {
  return new Promise((resolve, reject) => {
    rootState.axios.get(rootState.CONSTANTS.APISpecial + 'topicClass/getTopicClassList', {params}).then(res => {
      res = res.data
      resolve(res.topicClassVOList || [])
    }, () => {
      console.error('王者荣耀活动页请求错误 (╯‵□′)╯︵┻━┻')
      resolve([])
    })
  })
}

/**
 * 王者荣耀活动页 主页皮肤
 * @param state
 * @param commit
 * @param params
 * @returns {Promise} 无
 * @constructor
 */
api.MG_GET_KING_SKIN_HOME = function ({state, commit, rootState}, params) {
  return new Promise((resolve, reject) => {
    rootState.axios.get(rootState.CONSTANTS.APISpecial + 'skin/getSkinTypeList?limit=6', {}).then(res => {
      res = res.data
      resolve(res.skinEOList || [])
    }, () => {
      console.error('王者荣耀活动页请求错误 (╯‵□′)╯︵┻━┻')
      resolve([])
    })
  })
}

/**
 * 王者荣耀活动页皮肤专题
 * @param state
 * @param commit
 * @param params
 * @returns {Promise}
 * @constructor
 */
api.MG_GET_KING_SKIN = function ({state, commit, rootState}, params) {
  return new Promise((resolve, reject) => {
    rootState.axios.get(rootState.CONSTANTS.APISpecial + 'skin/getSkinList', {}).then(res => {
      res = res.data
      resolve(res.skinEOList || [])
    }, () => {
      console.error('王者荣耀活动页请求错误 (╯‵□′)╯︵┻━┻')
      resolve([])
    })
  })
}
/**
 * 王者荣耀专题列表请求
 * @param state
 * @param commit
 * @param params
 * @returns {Promise}
 * @constructor
 */
api.MG_GET_FIRST_KING_LIST = function ({state, commit, rootState}, params) {
  return new Promise((resolve, reject) => {
    rootState.axios.get(rootState.CONSTANTS.APISpecial + 'topicClass/getClassList', {params}).then(res => {
      res = res.body.data||[];
      resolve(res)
    }, () => {
      console.error('王者荣耀活动页请求错误 (╯‵□′)╯︵┻━┻')
      resolve([])
    })
  })
}

api.MG_GET_KING_LIST = function ({state, commit, rootState}, params) {
  return new Promise((resolve, reject) => {
    rootState.axios.get(rootState.CONSTANTS.APISpecial + 'topicClass/getClassGoodsList', {params}).then(res => {
      res = res.body.data||[];
      resolve(res) 
    }, () => {
      console.error('王者荣耀活动页请求错误 (╯‵□′)╯︵┻━┻')
      resolve([])
    })
  })
}
// /*主站Id转换m站GameId*/
// api.CHARGE_GAMEID = function ({state, commit, rootState}, params) {
//   return new Promise((resolve, reject) => {
//     rootState.axios.get(rootState.CONSTANTS.P30006 + 'category/getGameInfoByGameId', {params}).then(res => {
//       res = res.body
//       resolve(res)
//     }, () => {
//       console.error('转换游戏ID错误 (╯‵□′)╯︵┻━┻')
//       resolve([])
//     })
//   })
// }

export default {
  ...api
}
